﻿#include "includes\\InputStructures.fx"
#include "includes\\StateDefinitions.fx"

#define SS_FACTOR 16
#define SS_FACTOR_SQ (SS_FACTOR * SS_FACTOR)

texture2D xFinalImageHalf;
texture2D xFinalImageHalf2;
texture2D xFinalImageHalf3;

PsInput_PT SplitScreenVS(VsInput_PT input) 
{
	PsInput_PT output = (PsInput_PT)0;
    output.ScreenPos = input.Pos;
    output.UV = input.UV;
    return output;
}






float4 SplitScreenPS_withQCAA(PsInput_PT input) : SV_TARGET 
{
	float3 color = xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV).rgb * 4.0f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(1, 0)).rgb;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(1, 1)).rgb;

	color = color / 8.0f;
    return float4(color, 1.0f);
}






//float4 SplitScreenPS_withLOL(PsInput_PT input) : SV_TARGET 
//{
//	float w1 = 4.0f;
//	float w2 = 2.0f;
//	float w3 = 1.0f;
//	float3 color = xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV).rgb * w1;

//	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * w3;
//	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * w3;
//	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(1, 0)).rgb * w2;
//	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(1, 1)).rgb * w2;

//	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * w3;
//	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * w2;
//	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(1, 0)).rgb * w3;
//	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(1, 1)).rgb * w2;

//	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(2, 0)).rgb * w3;
//	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(2, 1)).rgb * w3;
//	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(0, 2)).rgb * w3;
//	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(1, 2)).rgb * w3;

//	color = color / (w1 + 4*w2 + 8*w3);
//    return float4(color, 1.0f);
//}



float4 SplitScreenPS_withLOL(PsInput_PT input) : SV_TARGET 
{
	float d = 2;
	float w2 = exp(-1*(0.25f/d));
	float w3 = exp(-1*(1.25f/d));

	float3 color = float3(0,0,0);
	
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * w2;
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(1, 0)).rgb * w2;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * w2;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * w2;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, -1)).rgb * w3;
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(1, -1)).rgb * w3;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(-1, 0)).rgb * w3;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(-1, 1)).rgb * w3;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * w3;
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(1, 1)).rgb * w3;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(1, 0)).rgb * w3;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(1, 1)).rgb * w3;

	color = color / (4*w2 + 8*w3);
    return float4(color, 1.0f);
}





float4 SplitScreenPS_withP112(PsInput_PT input) : SV_TARGET 
{
	float3 color = float3(0,0,0);
	
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.500f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.500f;

    return float4(color, 1.0f);
}




float4 SplitScreenPS_withP113(PsInput_PT input) : SV_TARGET 
{
	float3 color = float3(0,0,0);
	
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.320f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.345f;
	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.335f;

    return float4(color, 1.0f);
}




float4 SplitScreenPS_withP142(PsInput_PT input) : SV_TARGET 
{
	float3 color = float3(0,0,0);
	
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.074679f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.341459f;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(-1, 0)).rgb * 0.112832f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(-1, 0)).rgb * 0.050726;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * 0.113184f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * 0.051076;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(-1, 1)).rgb * 0.218571f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(-1, 1)).rgb * 0.037475f;

    return float4(color, 1.0f);
}




float4 SplitScreenPS_withP143(PsInput_PT input) : SV_TARGET 
{
	float3 color = float3(0,0,0);
	
	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.057758f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.027687f;
	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(0, 0)).rgb * 0.136271f;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(-1, 0)).rgb * 0.000038f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(-1, 0)).rgb * 0.112462f;
	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(-1, 0)).rgb * 0.151107f;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * 0.223377f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * 0.061529f;
	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(0, 1)).rgb * 0.050005f;

	color += xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(-1, 1)).rgb * 0.027062f;
	color += xFinalImageHalf2.Sample(PlanarSamplerPoint, input.UV, int2(-1, 1)).rgb * 0.138262f;
	color += xFinalImageHalf3.Sample(PlanarSamplerPoint, input.UV, int2(-1, 1)).rgb * 0.014443f;

    return float4(color, 1.0f);
}








float4 SplitScreenPS_withSS(PsInput_PT input) : SV_TARGET 
{
	float3 color = float3(0.0f, 0.0f, 0.0f);
	[unroll(SS_FACTOR)] for (int i = -SS_FACTOR/2; i < SS_FACTOR/2; i++)
	{
		[unroll(SS_FACTOR)]for (int j = -SS_FACTOR/2; j < SS_FACTOR/2; j++)
		{
			color = color + xFinalImageHalf.Sample(PlanarSamplerPoint, input.UV, int2(i, j)).rgb;
		}
	}
	color = color / SS_FACTOR_SQ;
    return float4(color, 1.0f);
}


//float4 SplitScreenPS_withSS(PsInput_PT input) : SV_TARGET 
//{
//	float3 color = float3(0.0f, 0.0f, 0.0f);
//	float divider = 0.0f;
//	[unroll(16)] for (int i = -SS_FACTOR; i < SS_FACTOR; i++)
//	{
//		[unroll(16)]for (int j = -SS_FACTOR; j < SS_FACTOR; j++)
//		{
//			float inten = exp(-1*((pow(float(i), 2) + pow(float(i), 2))/16));
//			color += inten * xFinalImageHalf.Sample(PlanarSampler, input.UV, int2(i, j)).rgb;
//			divider += inten;
//		}
//	}
//	color = color / divider;
//    return float4(color, 1.0f);
//}

//float4 SplitScreenPS_withSS(PsInput_PT input) : SV_TARGET 
//{
//	float3 color = float3(0.0f, 0.0f, 0.0f);
//	float divider = 0.0f;
//	float u = 16;
//	[unroll(8)] for (int i = 0; i < SS_FACTOR; i++)
//	{
//		[unroll(8)]for (int j = 0; j < SS_FACTOR; j++)
//		{
//			float inten = ((sin(i*3.141593/7)+1)/2) * ((sin(j*3.141593/7)+1)/2);
//			color += inten * xFinalImageHalf.Sample(PlanarSampler, input.UV, int2(i, j)).rgb;
//			divider += inten;
//		}
//	}
//	color = color / divider;
//    return float4(color, 1.0f);
//}


float4 SplitScreenPS(PsInput_PT input) : SV_TARGET 
{
    float3 color = xFinalImageHalf.Sample(PlanarSampler, input.UV).rgb;    
    return float4(color, 1.0f);
}